﻿<?php
/***********************************************************
    [EasyTalk] (C)2009 - 2011 nextsns.com
    This is NOT a freeware, use is subject to license terms

    @Filename SettingAction.class.php $

    @Author hjoeson $

    @Date 2011-01-09 08:45:20 $
*************************************************************/

class FuwuAction extends Action {

    public function _initialize() {
        //$this->tologin();
		A('Api')->tologin();
		parent::init();
        $this->ctent=D('Content');
        $this->assign('ctent',$this->ctent);
        $this->assign('usertemp',usertemp($this->my));
        $this->assign('menu','fuwud');
        $this->assign('subname','服务大厅');
		//$this->ctent->setmy($this->my);
    }

	// for fuwu info.. added 5/23/2011 luozhengfeng.
	public function index(){	
		$fuwuid=$_GET['id'];
		
		 if(!empty($fuwuid)) {	
				$fwview=D('FuwuView');
				$map['fuwuid']=$fuwuid;
				$result_fuwu=$fwview->where($map)->find();
				//echo $fuwuid;
				//dump($result_fuwu);
				$this->assign('vo_fuwu',$result_fuwu);
				//echo $vo_fuwu['fuwujiage'];
				$this->display();
				header('location:'.SITE_URL.'/Fuwu/dlist');
			}else{
				//Cookie::set('setok','setting3');
				//header('location:'.SITE_URL.'/Fuwu/dlist');
				//exit;
				$this->error('服务不存在！');
			}
		
	}

	 Public function dlist() {
        //$this->tologin();	
		$fwview=D('FuwuView');
		$conditionfuwu =''; //查看条件	
		$utrue=$_GET['ut'];		
		//echo $utrue;       	
        if ($utrue) {
            $conditionfuwu=$conditionfuwu.' and user_auth=1';
			$t_truename=1;				
        } else {
            $conditionfuwu=$conditionfuwu.'';
			$t_truename=0;				
        }

		$ydanbao=$_GET['ydb'];
		//echo $ydanbao;       
        if ($ydanbao=='0') {
            $conditionfuwu=$conditionfuwu.' and yuerdanbao=0'; 					
        } else if ($ydanbao=='0.2') {
            $conditionfuwu=$conditionfuwu.' and yuerdanbao=0.2';			
        } else {
            $conditionfuwu=$conditionfuwu.'';			
        }

		$haopinggs=$_GET['hpdj'];
		//echo $haopinggeshu;       
        if ($haopinggs=='1') {
            $conditionfuwu=$conditionfuwu.' and haopinggeshu>0'; 					
        } else if ($haopinggs=='2') {
            $conditionfuwu=$conditionfuwu.' and haopinggeshu>1';			
        } else {
            $conditionfuwu=$conditionfuwu.'';			
        }

		//接收并处理服务父子分类并定义搜索. Luozhengfeng 6/16/2011
		$fufenlei=$_GET['fufenlei'];
		$zifenlei=$_GET['zifenlei'];
        if ($fufenlei>0) {
			$conditionfuwu=$conditionfuwu.' and fuleibie='.$fufenlei;
			if ($zifenlei>0) {
				$conditionfuwu=$conditionfuwu.' and zileibie='.$zifenlei;				
			}else{
				$conditionfuwu=$conditionfuwu.''; 
			}            				
        }else{
            $conditionfuwu=$conditionfuwu.''; 	
        }
		
		//接收三级地区信息并定义搜索. Luozhengfeng 6/17/2011 00:00
		$lone=$_GET['lone'];
		$ltwo=$_GET['ltwo'];
		$lthree=$_GET['lthree'];
		if($lone>0){	
			$conditionfuwu=$conditionfuwu.' and city_code like '."'$lone %'";
			if($ltwo>0){
			    $conditionfuwu=$conditionfuwu.' and city_code like '."'%$ltwo %'";
				if($lthree>0){
					$conditionfuwu=$conditionfuwu.' and city_code like '."'%$lthree %'";
				}else{
				$conditionfuwu=$conditionfuwu.''; 
			} 
			}else{
				$conditionfuwu=$conditionfuwu.''; 
			}        
		}else{
			$conditionfuwu=$conditionfuwu.''; 	
		}
		

		//接收关键字信息并定义其搜索 Luozhengfeng 6/17/2011
		$kw=$_GET['kw'];
		if($kw){
			$conditionfuwu=$conditionfuwu.' and fuwuxiangqing like '."'%$kw%'".' or fuwubiaoti like '."'%$kw%'".' or Fuwu.user_name like '."'%$kw%'";
		}else{
			$conditionfuwu=$conditionfuwu.''; 	
		}
		
		//接收并定义我的服务 Luozhengfeng 6/17/2011
		$mines=$_GET['mines'];
		if($mines=="on"){
			$conditionfuwu=$conditionfuwu.' and Users.user_id='.$this->my['user_id'];
		}else{
			$conditionfuwu=$conditionfuwu.''; 	
		}

		//接收并定义同城的服务 Luozhengfeng 6/17/2011 过一段时间还要再加入我的亲友的查询方可.
		$tongc=-1;
		$tontongcgc=$_GET['tongc'];
		if($tongc>1){
			$conditionfuwu=$conditionfuwu.' and city_code like '."'%$tongc %'".' and shifouweiqinyou IS NULL '.' or suozaidizhi like '."'%$tongc'";
		}else if($tongc==0){
			$conditionfuwu=$conditionfuwu.' and city_code like '."'%$tongc %'";//如果没有值，则只显示自己的服务.后取消.
		}else {
            $condition='';
        }


		//echo $conditionfuwu;


		//引入服务技能列表
		$fuwufenlei=M('skill');
		$map['parent_id']=1;
		$result_fuwufenglei=$fuwufenlei->where($map)->findAll();
		$this->assign('vol_fuwu',$result_fuwufenglei);

		//引入地区列表
		$Province=M('region');
		$map['parent_id']=1;
		$result_regionsearch=$Province->where($map)->findAll();
		//echo json_encode($result);
		$this->assign('vol',$result_regionsearch);

		//echo  $utrue;
        //$fuwu=M('fuwu');
		import("@.ORG.Page"); //导入分页类
		$count = $fwview->where('Fuwu.fuwuid>1 '.$conditionfuwu)->count();    //计算总数		
		$p = new Page( $count,10 );
		$result_fuwu=$fwview->where('Fuwu.fuwuid>1 '.$conditionfuwu)->limit($p->firstRow.','.$p->listRows)->order('fuwuid desc')->findall(); //加了一个fuwu.fuwuid>1只是为了方便后面的and 这一个连接符. Luo zhengfeng 6/15/2011
		$p->setConfig('header','个服务');
		$p->setConfig('prev',"<");
		$p->setConfig('next','>');
		$p->setConfig('first','<<');
		$p->setConfig('last','>>');
		$page = $p->show ();
		$this->assign( "page_fuwu", $page );
		$this->assign('volfuwulist',$result_fuwu);	
		$this->assign('menu','fuwu');
		$this->assign('t_truename',$t_truename);
		$this->assign('t_ydanbao',$ydanbao);	
		$this->assign('t_haopinggs',$haopinggs);
		$this->assign('t_fufenlei',$fufenlei);
		$this->assign('t_zifenlei',$zifenlei);
		$this->assign('t_lone',$lone);
		$this->assign('t_ltwo',$ltwo);
		$this->assign('t_lthree',$lthree);
		$this->assign('t_kw',$kw);
		$this->assign('count',$count);
        $this->display('dlist');
    }

    public function maifuwu($fwid){
		//$this->tologin();
		$fwview=D('FuwuView');
		$fuwuid = $_GET['fwid'];
		//echo $fuwuid;
		if(!empty($fuwuid)){			
			$result_fuwud=$fwview->where("fuwuid='".$fuwuid."'")->find();			
			//dump($result_userd);					
			$this->assign('volfuwudan',$result_fuwud);		
			$this->assign('menu','fuwu');
			$this->display('maifuwu');			
		}else{
			exit('编辑项不存在！');
		}		
	}

	public function jia_fuwudan(){
		//开始定义服务单增加功能.6/19/2011 fuwudan表一共有21个项 6/23/2011 移到新加的fuwu功能中。
		$fuwudan =M('Fuwudan');
		$ctent=D('Content'); 		
		$data=array();
		 $fuwuid= $_POST["fuwuid"];
		 $data['fuwuid']= $fuwuid;
		 $data['user_id']= $_POST["userid"];

		if($_POST["userid"]==$this->my['user_id']){
			//Cookie::set('setok','setting3');
			//header('location:'.SITE_URL.'/Fuwu?id='.$fuwuid);
			//exit;
			$this->assign("jumpUrl",SITE_URL."/Fuwu/maifuwu/?fwid=".$fuwuid);
			$this->assign("waitSecond",1);			
			$this->error('自己不能购买自己的服务!');
			exit('自己不能购买自己的服务!');			
		}
		
		 $data['user_name']= $_POST["username"];
		 $data['purchase_userid']= $this->my['user_id'];
		 $data['purchase_username']= $this->my['user_name'];
		 $gaomai_num= $_POST["gaomai_num"];
		 $data['gaomai_num']= $gaomai_num;
		 //定义服务单标题并过滤.6/19/2011 LuoZhengfeng
		 $fuwudanbiaoti= daddslashes(clean_html(trim($_POST["fuwudan_biaoti"])));	
		  if(!$fuwudanbiaoti){
			  //Cookie::set('setok','setting3');
			  //header('location:'.SITE_URL.'/Fuwu/maifuwu?fwid='.$fuwuid);
			  //exit;
			  $this->assign("jumpUrl",SITE_URL."/Fuwu/maifuwu/?fwid=".$fuwuid);
			  $this->error('需要输入服务标题!');
			  exit;
			}
		 $data['fuwudan_biaoti']= $fuwudanbiaoti;
		 $data['zidingyiwenti']= $_POST["zidingyiwenti"];
		 $zidingyiwenti_reply= daddslashes(clean_html(trim($_POST["zidingyiwenti_reply"])));
		 //echo $zidingyiwenti_reply;
		 $data['zidingyiwenti_reply']= $zidingyiwenti_reply;
		 $data['yaoqiushijian']= $_POST["yaoqiushijian"];
		 $data['yingfujinger']= $_POST["gaomai_num"]*$_POST["yingfujinger2"];
		 $data['fuwudan_createtime']= time();
		 $data['fuwudan_updatetime']= time();
		 $data['fuwudan_status']= "新服务";
		 $data['shifoufukuan']= 0;
//		 echo $fuwuid;
//		 print_r($data);
		 
		 $list=$fuwudan->add($data);
		 if($list!==false){
			 $fuwu = M("fuwu"); //6/23/2011 23:59 更新 "sc_uid='".$this->my['user_id']."' AND replyid=0".$condition
			 $fuwu->setInc('yongfugoumaishu','fuwuid='.$fuwuid,$gaomai_num); 
			 if($_GET['pay']){ //这个本来是为了定义购买定单并付款的。但是发现一个表单无法有二个提交。所以只有暂时放弃了。代码留着。6/26/2011
				  $list_fuwudan=D('fuwudan')->where("user_id='".$this->my['user_id']."' AND fuwudan_biaoti=".$fuwudanbiaoti)->order('fuwudan_createtime desc')->find(); 
				  $this->assign('list_fuwudan',$list_fuwudan);
				  $fuwudan_fukuan = $list_fuwudan[fuwudanid];
				  D('Fuwudan')->fukuan($fuwudan_fukuan);
			 }
			 
			 //Cookie::set('setok','setting3');
			 //header('location:'.SITE_URL.'/Fuwudan/dlist');
			 $this->assign("jumpUrl",SITE_URL."/Fuwudan/dlist");
			 $this->success('服务单提交成功！');

			}else{			 
			 //Cookie::set('setok','setting3');
			 //header('location:'.SITE_URL.'/Fuwu?id='.$fuwuid);
			 //exit;
			 $this->assign("jumpUrl",SITE_URL."/Fuwu?id=".$fuwuid);
			 $this->error('服务单提交失败！');
			}
        
	}

	private function tologin() {
        if (!$this->my) {
            echo '<script type="text/javascript">window.location.href="'.SITE_URL.'/login"</script>';
            exit;
        }
    }
}
?>